package com.xiaoxiong.mami.dao.mapperImpl;

import com.xiaoxiong.mami.dao.daomain.Goods;
import com.xiaoxiong.mami.dao.mapper.GoodsMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by Administrator on 2017/7/27.
 */
@Mapper
public interface GoodsMapperImpl extends GoodsMapper {

    @Select("select * from goods order by updateTime desc ")
    public List<Goods> getGoodsList();

    @Select("select count(*) from goods where status = '1' ")
    public int getGoodsCount();

    @Select("select * from goods where goodsId = #{goodsId} limit 1")
    public Goods getGoodsById(String goodsId);

    @Select("<script>"
            + "SELECT *  FROM goods WHERE status = '1' and goodsId IN "
            + "<foreach item='item' index='index' collection='goodsIds' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    public List<Goods> getGoodsByGoodsIds(@Param("goodsIds") List<String> goodsIds);


    @InsertProvider(type = GoodMapperProvider.class, method = "insertGood")
    int insertGood(@Param("goodsId") String goodsId,@Param("title")  String title,
                   @Param("price") Double price, @Param("describe") String goodsDesc,
                   @Param("images") String images, @Param("thumbUrl") String thumbUrl,
                   @Param("sort") Integer sort, @Param("status") String status,
                   @Param("goodsImages") String goodsImages, @Param("stock")  Integer stock,
                   @Param("setMeal") String setMeal, @Param("buyNumMax") Integer buyNumMax,
                   @Param("goodsNumber") String goodsNumber);

    @UpdateProvider(type = GoodMapperProvider.class, method = "updateGoods")
    int updateGoods(@Param("goodsId") String goodsId,@Param("title")  String title,
                   @Param("price") Double price, @Param("goodsDesc") String goodsDesc,
                   @Param("images") String images, @Param("thumbUrl") String thumbUrl,
                   @Param("sort") Integer sort, @Param("status") String status,
                   @Param("goodsImages") String goodsImages, @Param("stock")  Integer stock,
                   @Param("setMeal") String setMeal, @Param("buyNumMax") Integer buyNumMax,
                   @Param("goodsNumber") String goodsNumber);
}
